<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <title>字典数据管理</title>
  <link rel="stylesheet" href="${ctx}/static/admin/layui/css/layui.css">
  <link rel="stylesheet" href="${ctx}/static/admin/css/common.css">
  <link rel="stylesheet" href="${ctx}/static/admin/css/sidebar.css">
  <link rel="stylesheet" href="${ctx}/static/admin/css/switch.css">
</head>
  <body>
  	<div class="layui-card-body">
	  <#button permission="" iconCls="layui-btn-success" size="layui-btn-sm" textName="添加" id="add"/>
	    <table class="layui-hide" id="dictdata_table"></table>
	</div>
  </body>
</html>
<script src="${ctx}/static/admin/layui/layui.js"></script>
<script src="${ctx}/static/admin/js/common.js"></script>
<script type="text/html" id="enabled">
  <input type="checkbox" name="status" lay-filter="status" value="{{d.status}}" lay-skin="switch" lay-text="启用|禁用" {{ d.status == 1 ? 'checked' : '' }}>
</script>
<script type="text/html" id="toolbar">
  <#button permission="" iconCls="layui-btn-warm" size="layui-btn-xs" textName="编辑" event="edit"/>
</script>
<script type="text/javascript">
layui.use(['table','layer','jquery','element','form'], function(){
	var $ = jQuery = layui.$;
	var table = layui.table;
	var layer = layui.layer;
	var element = layui.element;
    var form = layui.form;
	var tableIns = table.render({
		elem: '#dictdata_table',
	    cellMinWidth: 50,
	    size:'sm',
	    even:true,
	    url: '${ctx}/sys_admin/sys/dict/getDataList?typeValue=${typeValue}',
	    height:'full-70',
	    page: true,
	    cols: [[
          {type: 'numbers'},
          {field: 'id', title: 'ID',hide:true},
	      {field: 'name', title: '数据名', width:300},
	      {field: 'value', title: '数据值',width:300},
	      {field: 'seq', title: '排序',width:60},
	      {field: 'des', title: '描述',width:180},
	      {field: 'status', title:'状态', templet: '#enabled', unresize: true,width:90},
	      {title: '操作', width: 100, fixed: 'right', align:'center',toolbar: '#toolbar'}
	    ]],
	    where: {
	    	sort: 'seq',
	    	order: 'asc',
	    },
        page: {
            first: '首页',
            last: '尾页',
            prev: '上一页',
            next: '下一页',
            layout: ['limit', 'count', 'prev', 'next', 'page'] //自定义分页布局
        }
	});
	table.on('tool', function(obj){
	    var data = obj.data;
	    if(obj.event === 'edit'){
	    	parent.layer.open({
		  		  type: 2,
		  		  area: ['500px', '350px'],
		  		  fixed: false, //不固定
		  		  maxmin: true,
		  		  content: '${ctx}/sys_admin/sys/dict/dataform?id='+data.id+'&typeValue=${typeValue}',
			  		btn: ['保存', '关闭'],
		  	  		yes: function(index, layero){
			  	  		var iframeWin = layero.find('iframe')[0];//得到iframe页的窗口对象，执行iframe页的方法：
				  		iframeWin.contentWindow.table = tableIns;
				  		layero.find('iframe').contents().find('#submit-btn').click();
				  	},
				  	btn2: function(index, layero){
			  			var index = layer.getFrameIndex(window.name);
						layer.close(index); //再执行关闭   
				  	}
		  		});
	    }
	});

	form.on('switch(status)', function(data){
		var selectIfKey = data.othis;                                                
		var parentTr = selectIfKey.parents("tr");                                 
		var parentTrIndex = parentTr.attr("data-index");                          
		var id = parentTr.find(('td:eq(1)')).text().trim();
		var visible = 0;
		if(data.elem.checked){visible = 1;}
		$.post('${ctx}/sys_admin/sys/dict/visibleData', {id: id, visible: visible}, function() {}, 'json');
	}); 
	
	$("#add").on('click', function() {
		parent.layer.open({
			type: 2,
			area: ['500px', '350px'],
			fixed: false, //不固定
			maxmin: true,
			content: '${ctx}/sys_admin/sys/dict/dataform?typeValue=${typeValue}',
	  		btn: ['保存', '重置', '关闭'],
		  	yes: function(index, layero){
		  		var iframeWin = layero.find('iframe')[0];//得到iframe页的窗口对象，执行iframe页的方法：
		  		iframeWin.contentWindow.table = tableIns;
		  		layero.find('iframe').contents().find('#submit-btn').click();
		  	},
		  	btn2: function(index, layero){
		  		layero.find('iframe').contents().find('#reset-btn').click();
		  		return false;
		  	},
		  	btn3: function(index, layero){
	  			var index = layer.getFrameIndex(window.name);
				layer.close(index); //再执行关闭   
		  	}
		});
	});

});
</script>